package E2013;

class MyException extends Exception{  //继承自Exception类
    String error;
    public MyException(int m){
        error = "数字不能大于1000";
    }
}

class Student{
    // 定义方法声明可以抛出异常
    public void speak(int m) throws MyException{
        if (m>1000){
            MyException myException = new MyException(m);
            throw myException;  // 真正抛出了异常
        }else{
            System.out.println(m);
        }
    }
}

public class e07 {
    public static void main(String[] args) {
        Student stu = new Student();
        try {
            stu.speak(600);
            stu.speak(1200);
        } catch (MyException e) {
            e.printStackTrace();
            System.out.println(e.error);
        }
    }

}
